% Remember to use the lgrind style

\Head{}
\File{./java/Utility.java}{2006}{4}{27}{19:09}{4164}
\L{\LB{\C{}/*}}
\L{\LB{_*_Utility.java}}
\L{\LB{_*}}
\L{\LB{_*_Created_on_January_5,_2006,_10:55_AM}}
\L{\LB{_*/\CE{}}}
\L{\LB{}}
\L{\LB{\K{package}_\V{project01};}}
\L{\LB{}}
\L{\LB{\K{import}_\V{java}.\V{awt}.\V{Dimension};}}
\L{\LB{\K{import}_\V{java}.\V{io}.*;}}
\L{\LB{\K{import}_\V{java}.\V{net}.*;}}
\L{\LB{\K{import}_\V{java}.\V{util}.\V{LinkedList};}}
\L{\LB{\K{import}_\V{java}.\V{util}.\V{jar}.*;}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\C{}/**}}
\L{\LB{_*}}
\L{\LB{_*_\CE{}\V{author}_\V{Ian}_\V{Melnick}}}
\L{\LB{\C{}*/\CE{}}}
\L{\LB{\K{public}_\K{class}_\V{Utility}_\{}\Tab{26}{}}
\index{getArgs}\Proc{getArgs}\L{\LB{}\Tab{4}{\K{public}_\K{static}_\V{Args}_\V{getArgs}(\V{String}[\,]_\V{args},_\V{Main}_\V{prog})_\{}}
\L{\LB{}\Tab{8}{\V{Args}_\V{a}_=_\K{new}_\V{Args}();}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\K{if}(\V{args}.\V{length}\>\N{0}_\&\&_(\V{args}[\N{0}].\V{equals}(\S{}\3\-h\3\SE{})_\|\,\|_\V{args}[\N{0}].\V{equals}(\S{}\3\-\-help\3\SE{})))_\{}}
\L{\LB{}\Tab{12}{\V{System}.\V{out}.\V{println}(\S{}\3Usage:_java_\-jar_Project01.jar_\<Editor\|Router\>_\<map\>_\<width\>_\<height\>\3\SE{});}}
\L{\LB{}\Tab{12}{\V{System}.\V{exit}(\N{0});}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\K{if}(\V{args}.\V{length}\>\N{0}_\&\&_\V{args}[\N{0}]!=\K{null})_\{}}
\L{\LB{}\Tab{12}{\K{try}_\{}}
\L{\LB{}\Tab{16}{\V{a}.\V{mode}_=_\V{a}.\V{mode}.\V{valueOf}(\V{args}[\N{0}]);}}
\L{\LB{}\Tab{12}{\}_\K{catch}_(\V{IllegalArgumentException}_\V{err})_\{}}
\L{\LB{}\Tab{16}{\V{System}.\V{out}.\V{print}(\S{}\3Can{'}t_do_\3\SE{}_+_\V{args}[\N{0}]_+_\S{}\3,_but_I_do_know_these:_\3\SE{});}}
\L{\LB{}\Tab{16}{\K{for}(\V{Main}.\V{AppModes}_\V{op}_\V{:}_\V{Main}.\V{AppModes}.\V{values}())_\{}}
\L{\LB{}\Tab{20}{\V{System}.\V{out}.\V{print}(\V{op}_+_\S{}\3_\3\SE{});}}
\L{\LB{}\Tab{16}{\}}}
\L{\LB{}\Tab{16}{\V{System}.\V{exit}(\N{1});}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{8}{\K{else}_\{}}
\L{\LB{}\Tab{12}{\V{a}.\V{mode}_=_\V{a}.\V{mode}.\V{valueOf}(\S{}\3Router\3\SE{});}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\K{if}(\V{args}.\V{length}\>\N{1}_\&\&_\V{args}[\N{1}]!=\K{null})_\{}}
\L{\LB{}\Tab{12}{\V{a}.\V{map}_=_\V{args}[\N{1}];}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{8}{\K{else}_\{}}
\L{\LB{}\Tab{12}{\K{try}_\{}}
\L{\LB{}\Tab{16}{\V{a}.\V{map}_=_\V{prog}.\V{getParameter}(\S{}\3m\3\SE{});}}
\L{\LB{}\Tab{12}{\}_\K{catch}_(\V{java}.\V{lang}.\V{NullPointerException}_\V{e})_\{}}
\L{\LB{}\Tab{16}{\V{a}.\V{map}_=_\S{}\3scieng\_100\3\SE{};}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\C{}//_When_called_as_an_applet,_it_will_get_width/height_properties\CE{}}}
\L{\LB{}\Tab{8}{\C{}//_the_normal_way;_only_init()_will_be_called,_so_we_don{'}t_have_to\CE{}}}
\L{\LB{}\Tab{8}{\C{}//_worry_about_main().\CE{}}}
\L{\LB{}\Tab{8}{\K{if}(\V{args}.\V{length}\>\N{3}_\&\&_(\V{args}[\N{2}]!=\K{null}_\&\&_\V{args}[\N{3}]!=\K{null}))_\{}}
\L{\LB{}\Tab{12}{\V{a}.\V{resolution}_=_\K{new}_\V{Dimension}(\V{Integer}.\V{parseInt}(\V{args}[\N{2}]),_}}
\L{\LB{}\Tab{41}{\V{Integer}.\V{parseInt}(\V{args}[\N{3}]));}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{8}{\K{else}_\{}}
\L{\LB{}\Tab{12}{\V{a}.\V{resolution}_=_\K{new}_\V{Dimension}(\N{900},\N{700});}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\K{return}_\V{a};}}
\L{\LB{}\Tab{4}{\}}}
\L{\LB{}\Tab{4}{}}
\index{map\_images}\Proc{map\_images}\L{\LB{}\Tab{4}{\K{public}_\K{static}_\V{String}[\,]_\V{map\_images}(\V{String}_\V{matching})_\{}}
\L{\LB{}\Tab{8}{\K{if}(\V{matching}==\K{null})_\V{matching}_=_\S{}\3\3\SE{};}}
\L{\LB{}\Tab{8}{\K{final}_\V{String}_\V{mapDescrip}_=_\V{matching};}}
\L{\LB{}\Tab{8}{\K{final}_\V{String}_\V{lookForDir}_=_\S{}\3images/\3\SE{};}}
\L{\LB{}\Tab{8}{\K{final}_\V{String}_\V{mapPrefix}}\Tab{32}{=_\S{}\3map\_\3\SE{};}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\C{}//_Open_directory_containing_map_images\CE{}}}
\L{\LB{}\Tab{8}{\C{}//_If_running_from_JAR,_must_extract_names_from_JAR.\CE{}}}
\L{\LB{}\Tab{8}{\C{}//_Otherwise,_just_scan_directory_containing_images.\CE{}}}
\L{\LB{}\Tab{8}{\V{String}_\V{imgLoc}_=_\V{Utility}.\K{class}.\V{getResource}(\V{lookForDir}).\V{toString}();}}
\L{\LB{}\Tab{8}{\K{if}(\V{imgLoc}.\V{startsWith}(\S{}\3jar:\3\SE{}))_\{}}
\L{\LB{}\Tab{12}{\V{LinkedList}\<\V{String}\>_\V{imgList}_=_\K{new}_\V{LinkedList}\<\V{String}\>();}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\V{URI}_\V{filePath}_=_\V{URI}.\V{create}(\V{imgLoc}.\V{split}(\S{}\3!\3\SE{})[\N{0}].\V{substring}(\N{4}));}}
\L{\LB{}\Tab{12}{\V{JarInputStream}_\V{jin}_=_\K{null};}}
\L{\LB{}\Tab{12}{\K{try}_\{}}
\L{\LB{}\Tab{16}{\V{jin}=\K{new}_\V{JarInputStream}(\K{new}_\V{FileInputStream}(\K{new}_\V{File}(\V{filePath})));}}
\L{\LB{}\Tab{12}{\}_\K{catch}_(\V{Exception}_\V{er})_\{}}
\L{\LB{}\Tab{16}{\V{Errors}.\V{debug}(\V{er});}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\V{JarEntry}_\V{jar}_=_\K{null};}}
\L{\LB{}\Tab{12}{\V{String}_\V{pathParts}[\,]_=_\K{null};}}
\L{\LB{}\Tab{12}{\K{try}_\{}}
\L{\LB{}\Tab{16}{\K{while}(_(\V{jar}_=_\V{jin}.\V{getNextJarEntry}())_!=_\K{null}_)}}
\L{\LB{}\Tab{20}{\K{if}(\V{jar}.\V{getName}().\V{contains}(\V{lookForDir}_+_\V{mapPrefix})_\&\&_(\V{pathParts}_=_\V{jar}.\V{getName}().\V{split}(\S{}\3/\3\SE{}))!=\K{null})}}
\L{\LB{}\Tab{24}{\V{imgList}.\V{add}(\V{pathParts}[\V{pathParts}.\V{length}\-\N{1}]);}}
\L{\LB{}\Tab{12}{\}_\K{catch}_(\V{Exception}_\V{er})_\{}}
\L{\LB{}\Tab{16}{\V{Errors}.\V{debug}(\V{er});}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\K{return}_\V{imgList}.\V{toArray}(\K{new}_\V{String}[\N{0}]);}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{8}{\K{else}_\{}}
\L{\LB{}\Tab{12}{\V{File}_\V{imageDir}_=_\K{new}_\V{File}(\V{URI}.\V{create}(\V{imgLoc}));}}
\L{\LB{}\Tab{12}{\K{if}(!\V{imageDir}.\V{isDirectory}())}}
\L{\LB{}\Tab{16}{\V{System}.\V{err}.\V{println}(\V{imageDir}_+_\S{}\3_is_not_a_directory!_Continuing.\,.\,.\3\SE{});}}
\L{\LB{}\Tab{16}{}}
\L{\LB{}\Tab{12}{\C{}//_Only_allow_map_images_from_same_building_as_current_map\CE{}}}
\L{\LB{}\Tab{12}{\C{}//_FilenameFilter:_http://javaalmanac.com/egs/java.io/GetFiles.html\CE{}}}
\L{\LB{}\Tab{12}{\C{}//_imc.map().split(\3\_\3)[0]}\Tab{40}{==_\_building\CE{}}}
\L{\LB{}\Tab{12}{\V{FilenameFilter}_\V{filter}_=_\K{new}_\V{FilenameFilter}()_\{}}
\L{\LB{}\Tab{16}{\K{public}_\K{boolean}_\V{accept}(\V{File}_\V{dir},_\V{String}_\V{name})_\{}}
\L{\LB{}\Tab{20}{\K{return}_\V{name}.\V{startsWith}(\V{mapPrefix}_+_\V{mapDescrip});}}
\L{\LB{}\Tab{16}{\}}}
\L{\LB{}\Tab{12}{\};}}
\L{\LB{}\Tab{12}{\K{return}_\V{imageDir}.\V{list}(\V{filter});}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\C{}//return_null;\CE{}}}
\L{\LB{}\Tab{4}{\}}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\K{class}_\V{Args}_\{}}
\L{\LB{}\Tab{4}{\K{public}_\V{Main}.\V{AppModes}_\V{mode};}}
\L{\LB{}\Tab{4}{\K{public}_\V{Dimension}_\V{resolution};}}
\L{\LB{}\Tab{4}{\K{public}_\V{String}_\V{map};}}
\L{\LB{\}}}
